package com.duobaoyu.dby.supply.biz.service.queue.core;

import com.duobaoyu.dby.common.core.constant.CommonConstants;
import com.duobaoyu.dby.supply.core.common.exception.CustomAssert;
import lombok.Getter;

import java.util.Optional;

/**
 * Created by shuming on 2023/9/27 14:33
 */
@Getter
public class DistributionQueueMessage {

    /**
     * 主题名称
     */
    private final String topicName;
    /**
     * 业务场景（自动订单）
     */
    private final Integer bizScenario;
    /**
     * 业务编码
     */
    private final String bizCode;
    /**
     * 延迟时间 (毫秒)
     */
    private final Long delayTime;
    /**
     * 创建时间
     */
    private final Long createTime;

    /**
     * 触发时间
     */
    private final Long triggerTime;

    /**
     * 内容
     */
    private final String data;

    public DistributionQueueMessage(String topicName,
                                    Integer bizScenario,
                                    String bizCode,
                                    Long delayTime,
                                    String data) {
        CustomAssert.hasLength(topicName, "topicName is required");
        CustomAssert.notNull(bizScenario, "bizScenario is required");
        CustomAssert.notNull(data, "data is required");
        this.topicName = topicName;
        this.bizScenario = bizScenario;
        this.bizCode = bizCode;
        this.data = data;
        this.delayTime = Optional.ofNullable(delayTime).orElse(Long.valueOf(CommonConstants.ZERO));
        this.createTime = System.currentTimeMillis();
        this.triggerTime = createTime + this.delayTime;
    }


    @Override
    public String toString() {
        return "DistributionQueueMessage{" +
                "topicName='" + topicName + '\'' +
                ", bizScenario=" + bizScenario +
                ", bizCode='" + bizCode + '\'' +
                ", delayTime=" + delayTime +
                ", createTime=" + createTime +
                ", triggerTime=" + triggerTime +
                ", data='" + data + '\'' +
                '}';
    }
}
